 <template>
  <div class="index-box" ref="index">
    <el-row :gutter="10">
      <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
        <div class="moneyTotal" ref="topData">
            <div class="item">
              <div class="money">{{topData.goodsSaleTotal}}</div>
              <div class="text">商品成交总计(单)</div>
            </div>
            <div class="item">
              <div class="money">{{topData.goodsTotalAmount}}</div>
              <div class="text">商品总金额(元)</div>
            </div>

        </div>
        <div class="search" ref="search">
          <el-form :inline="true" :model="searchForm" size="small" ref="searchForm" @submit.native.prevent
            class="demo-form-inline" id="searchBox">
            <el-form-item prop="goodsCode">
                <el-input v-model="searchForm.goodsCode" clearable placeholder="商品编号"></el-input>
            </el-form-item>
            <el-form-item prop="goodsName">
                <el-input v-model="searchForm.goodsName" clearable placeholder="商品名称"></el-input>
            </el-form-item>
            <el-form-item prop="time">
               <el-date-picker v-model="time" type="daterange" align="right" unlink-panels range-separator="至"
                 start-placeholder="开始日期" end-placeholder="结束日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
                 :picker-options="pickerOptions">
               </el-date-picker>
            </el-form-item>

            <el-form-item class="clearfix">
              <el-button type="primary" @click="handleSearch()" icon="el-icon-search">搜索</el-button>
              <el-button icon="el-icon-refresh" size="small" @click="resetSearch">重置</el-button>

            </el-form-item>
            <div class="actionBtnRight" style="margin-left:auto">
                <MyRefresh></MyRefresh>
                <MyTableColumnSet :tableColumn.sync="tableColumn" :hideTableColumn.sync="hideTableColumn" :tableColumnType.sync="tableColumnType"></MyTableColumnSet>
            </div>
          </el-form>
        </div>
        <div class="table" ref="table">
          <el-table :data="dataList" style="width: 100%;" :height="tableHeight" v-loading="loading" border stripe>

            <el-table-column prop="img" label="商品图片" v-if="!hideTableColumn.includes('img')" width="100" align="center">
              <template #default="scope">
                 <el-image :src="scope.row.goodsImage" fit="fill" v-image-preview="scope.row.goodsImage" class="img"></el-image>
              </template>
            </el-table-column>
            <el-table-column prop="goodsCode" label="商品编号" v-if="!hideTableColumn.includes('orderCode')" align="center"></el-table-column>
            <el-table-column prop="goodsName" label="商品名称" v-if="!hideTableColumn.includes('shopName')" align="center"></el-table-column>
            <el-table-column prop="productName" label="商品分类" v-if="!hideTableColumn.includes('orderType')" align="center">
              <template #default="scope">
                <span v-if="scope.row.productParentName">{{scope.row.productParentName}}>></span><span>{{scope.row.productName}}</span>
              </template>
            </el-table-column>

            <el-table-column prop="soldNum" label="商品成交量(件)" v-if="!hideTableColumn.includes('shopNumber')" align="center"></el-table-column>
            <el-table-column prop="goodsPrice" label="商品合计金额(元)" v-if="!hideTableColumn.includes('orderAllMoney')" align="center"></el-table-column>
          </el-table>
        </div>
        <div class="page" ref="page">
          <MyPagination
            :total="total"
            :page.sync="searchForm.pageNum"
            :limit.sync="searchForm.pageSize"
            @pagination="dataInfo"
          />
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  import common from '@/api/api';
  import {
    goodsSalesGetList,
    getGoodsSalesQuery
  } from '@/api/getData'
  import option from '../../common/option.js';

  export default {
    data() {
      return {
        loading: false,
        time:[],
        searchForm: {
          goodsCode:'',
          goodsName:'',
          pageNum: 1,
          pageSize: 20,
        },
        tableColumn:[{
            name:'商品图片',
            value:'img'
        },{
            name:'商品编号',
            value:'orderCode'
        },{
            name:'商品名称',
            value:'goodsName'
        },{
            name:'商品分类',
            value:'productName'
        },{
            name:'商品成交量',
            value:'soldNum'
        },{
            name:'订单合计金额(元)',
            value:'goodsPrice'
        }],
        hideTableColumn:[],/*自定义表格列需要隐藏的*/
        tableColumnType:'staffManagement',/*自定义表格列类型传参*/
        tableHeight:0,//table 高度
        statusRow:{},
        dataList:[],
        total: 0,
        topData:{}
      }
    },
    computed:{
      pickerOptions: () => {
        return option.pickerOptions;
      }
    },
    mounted() {
      // this.getTopDataFN();
      // this.dataInfo();
      this.$nextTick(() => {
          this.tableHeight = this.$refs.index.offsetHeight - this.$refs.topData.offsetHeight - this.$refs.search.offsetHeight - this.$refs.page.offsetHeight - 65;
      })
    },
    methods: {
      getTopDataFN(){
        let data = this.addDateRange(this.searchForm, this.time, 'startTime', 'endTime');
        getGoodsSalesQuery(data).then((res)=>{
          this.topData = res.data;
        })
      },
      resetSearch(){
        this.time = [];
        this.resetForm('searchForm');
        this.getTopDataFN();
        this.dataInfo();
      },
      handleSearch(){
          this.searchForm.pageNum = 1;
          this.getTopDataFN();
          this.dataInfo();
      },
      async dataInfo() {
        try {
          let data = this.addDateRange(this.searchForm, this.time, 'startTime', 'endTime');
          this.loading = true;
          const result = await goodsSalesGetList(data);
          if (result.code == 200) {
            this.total = result.total;
            this.dataList = result.rows;
          } else {
            this.$message.error(result.msg);
          }
          this.loading = false;
        } catch (err) {
          this.loading = false;
          console.log(err)
        }
      },

    }
  }
</script>

<style scoped lang="scss">

  .el-table .el-dropdown-link{
      cursor: pointer;
      color: #61997A;
      margin-left: 5px;
  }
    .leftDialog{
      height:540px;
      overflow-y: auto;
    }
    .activeVerticalBox .activeItem{
      color:#61997A;
      cursor: pointer;
      margin: 0px;
      text-align: center;
      height:20px;
      line-height: 20px;
    }
    .activeVerticalBox .el-dropdown{
      display: flex;
      justify-content: center;
      color:#61997A;
      cursor: pointer;
    }
    .activeCheckedBox{
      border-top: 1px solid #ddd;
      padding:10px;
      height:52px;
      .el-tag{
        margin-right:10px;
      }
    }
    .rateBox /deep/ .el-rate__icon{
      margin-right: 0px;
    }
    .rateBox>p{
      margin: 0px;
    }
    .rateBox>p> /deep/ .el-rate{
      height:25px;
      line-height:25px;
      display:flex;
    }
    .rateBox>p> /deep/ .el-rate .el-rate__item{
      display:flex;
      align-items: center;
    }
    .rateBox .rateText{
      width:60px;
    }
    .rateBox .content{
      display: flex;
    }
    .rateBox .el-tooltip{
      width: 100px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      display: inline-block;
    }
</style>
